package zh.keep.all.account

import zh.keep.all.account.AuthenticationService.AccountAuthenticator
import android.content.Intent
import android.os.IBinder
import android.accounts.AbstractAccountAuthenticator
import android.accounts.AccountAuthenticatorResponse
import android.os.Bundle
import kotlin.Throws
import android.accounts.NetworkErrorException
import android.accounts.Account
import android.app.Service
import android.content.Context

/**
 * 用于账户同步拉活
 */
class AuthenticationService : Service() {
    /**
     * 账户验证器
     */
    var mAccountAuthenticator: AccountAuthenticator? = null
    override fun onBind(intent: Intent): IBinder? {
        return mAccountAuthenticator!!.iBinder
    }

    override fun onCreate() {
        super.onCreate()
        // 创建账户验证器
        mAccountAuthenticator = AccountAuthenticator(this)
    }

    /**
     * 账户验证器
     */
    inner class AccountAuthenticator(context: Context?) : AbstractAccountAuthenticator(context) {
        override fun editProperties(
            response: AccountAuthenticatorResponse,
            accountType: String
        ): Bundle? {
            return null
        }

        @Throws(NetworkErrorException::class)
        override fun addAccount(
            response: AccountAuthenticatorResponse,
            accountType: String,
            authTokenType: String,
            requiredFeatures: Array<String>,
            options: Bundle
        ): Bundle? {
            return null
        }

        @Throws(NetworkErrorException::class)
        override fun confirmCredentials(
            response: AccountAuthenticatorResponse,
            account: Account,
            options: Bundle
        ): Bundle? {
            return null
        }

        @Throws(NetworkErrorException::class)
        override fun getAuthToken(
            response: AccountAuthenticatorResponse,
            account: Account,
            authTokenType: String,
            options: Bundle
        ): Bundle? {
            return null
        }

        override fun getAuthTokenLabel(authTokenType: String): String? {
            return null
        }

        @Throws(NetworkErrorException::class)
        override fun updateCredentials(
            response: AccountAuthenticatorResponse,
            account: Account,
            authTokenType: String,
            options: Bundle
        ): Bundle? {
            return null
        }

        @Throws(NetworkErrorException::class)
        override fun hasFeatures(
            response: AccountAuthenticatorResponse,
            account: Account,
            features: Array<String>
        ): Bundle? {
            return null
        }
    }
}